// ==UserScript==
// @name           FlickrLightBox
// @version        1.0.0
// @description    Flickr with LightBox 
// @include        http://www.flickr.com/*
// ==/UserScript


(function () {
    var head = document.getElementsByTagName("head")[0];
    var s = document.createElement("script");
    s.type = "text/javascript";
    s.src = "http://akihito.xii.jp/lightbox/lightbox.js";
    head.appendChild(s);

    var css = document.createElement("link");
    css.rel = "stylesheet";
    css.type = "text/css";
    css.href = "http://akihito.xii.jp/lightbox/lightbox.css";
    head.appendChild(css)

    var photolist = new Array();
    var image = document.getElementsByTagName('img');
    for(i=0;i<image.length;i++) {
        var alt = image[i].alt;
        var src = image[i].src;
        src = src.split('_m.jpg').join('.jpg')
        photolist[alt] = src;
    }

    var anchor = document.getElementsByTagName('a');
    for(i=0;i<anchor.length;i++) {
        if(anchor[i].href.match(new RegExp('/photos/')) && anchor[i].title != "" ){
            var title = anchor[i].title;
            anchor[i].setAttribute("rel","lightbox");
            anchor[i].setAttribute("href",photolist[title]);
        }
    }

})();


